// FileUpload.h: interface for the FileUpload class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_FILEUPLOAD_H__4EA3F46C_1BE9_489E_87F1_9A28DFCA153A__INCLUDED_)
#define AFX_FILEUPLOAD_H__4EA3F46C_1BE9_489E_87F1_9A28DFCA153A__INCLUDED_

#undef Rectangle
#include <curl/curl.h>
#include "FileUploadListener.h"
#include <juce.h>

class FileUpload  
{
	public:
		FileUpload() throw();
		~FileUpload();
		void cleanup();

		static const StringArray getPossibleProtocols()
		{
			StringArray ar;
			curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);

			int x=0;

			do 
			{
				x++;
				if (data->protocols[x])
				{
					ar.add (data->protocols[x]);
				}
			} 
			while (data->protocols[x] != NULL);

			return (ar);
		}

		bool setUrl (String url);
		bool post();
		bool setFormField (String formVarName, String formVarValue);
		bool setFormField (String formVarName, File formVarValue);
		void addUploadListener (FileUploadListener *newListener);
		static int progressCallback (void* data, double dltotal, double dlnow, double ultotal, double ulnow);
		static int writeFunction (void *ptr, size_t size, size_t nmemb, void *stream);
		String getLastError();
		bool setProxy (String url);
		bool setProxyType (int t);

		enum proxyTpe
		{
			proxyHTTP,
			proxySOCKS5,
			proxySOCKS4,
			proxySOCKS4a
		};

	private:
		CURL *curl;
		struct curl_httppost *formPost;
		struct curl_httppost *lastFormPost;
		SortedSet <void*> uploadListeners;
		String currentError;
};

#endif
